home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1997: The Complete Utilities Toolkit / macworld-complete-utilities-1997.iso / Programming / Little Smalltalk v3.1.5 / C Source / Sources / CLStApp.cp < prev    next >
Encoding:
Text File  |  1995-06-20  |  6.3 KB  |  224 lines  |  [TEXT/KAHL]

  1. //=============================================================================
  2. //    Little Smalltalk, version 3
  3. //    Written by Tim Budd, Oregon State University, July 1988
  4. //
  5. //    Symantec Think Class Library interface code 
  6. //        ©Julian Barkway, April 1994, all rights reserved.
  7. //
  8. //    CLStApp.cp
  9. //    ----------
  10. //    This class performs basic initialisation and other stuff relating to the
  11. //    Little Smalltalk TCL interface.
  12. //
  13. //    
  14. //    Version History
  15. //    ---------------
  16. //    3.1.4 - First general release
  17. //    3.1.5 - Modified to support command-key equivalents for Smalltalk menus
  18. //=============================================================================
  19.  
  20. #include <string.h>
  21. #include "CLStApp.h"
  22. #include "CLStSwitchboard.h"
  23. #include "CBartender.h"
  24. #include "Global.h"
  25. #include "Constants.h"
  26. #include "Commands.h"
  27. #include "LStResources.h"
  28.  
  29. extern    OSType        gSignature;
  30. extern    CBartender    *gBartender;
  31.  
  32. #define        kExtraMasters        10
  33. #define        kRainyDayFund        45000
  34. #define        kCriticalBalance    40000
  35. #define        kToolboxBalance        20000
  36.  
  37. CLStApp        *gSmalltalk;
  38.  
  39.  
  40. //=============================================================================
  41. // Application initialization. Invoke IApplication to perform all ToolBox init
  42. // calls, allocate memory and other stuff.
  43. //=============================================================================
  44. void CLStApp::ILStApp(void)
  45. {
  46.     Handle                versH;
  47.  
  48.     CApplication::IApplication (kExtraMasters, kRainyDayFund,
  49.                                 kCriticalBalance, kToolboxBalance);
  50.     gSmalltalk = this;
  51.     ErrorSound (NULL);                            // Disable Alert beep
  52.     
  53.     versH = GetResource ('vers', kVersionRes);    // Get the version number
  54.     BlockMove ((*versH) + 6, versionStr, (Size)(*((*versH) + 6) + 1));
  55. }
  56.  
  57.  
  58. //=============================================================================
  59. // Set up the types of files Li'l Smalltalk knows about as well as the 
  60. // application signature.
  61. //=============================================================================
  62. void CLStApp::SetUpFileParameters (void)
  63. {
  64.     inherited::SetUpFileParameters();
  65.  
  66.     sfNumTypes      = kNumTypes;        /* Number of file types in array (max 4) */
  67.     sfFileTypes [0] = kTextType;        /* Text */
  68.     sfFileTypes [1] = kSysImageType;    /* System Image files */
  69.     
  70.     gSignature = kCreator;
  71. }
  72.  
  73.  
  74. //={OVERRIDE}==================================================================
  75. // Store the command for interface processing
  76. //=============================================================================
  77. void CLStApp::DoCommand (long commandNo)
  78. {
  79.     if (commandNo == cmdAbout) {
  80.         DoAbout (0L);
  81.         return;
  82.     }
  83.     if (commandNo < 0) {
  84.         menuID   = HiShort (-commandNo);
  85.         menuItem = LoShort (-commandNo); 
  86.         if (menuID == MENUapple) {
  87.             inherited::DoCommand (commandNo);
  88.             gSmalltalk->smalltalkCmd = FALSE;
  89.             return;
  90.         }
  91.         gSmalltalk->lastEvent.what = mouseDown; // Restore the action removed
  92.                                                  // by LSTSwitchboard::GetAnEvent ()
  93.         gSmalltalk->winPart = inMenuBar;        // v3.1.5 - added for command key support
  94.         gSmalltalk->smalltalkCmd = TRUE;
  95.         return;
  96.     }
  97.                                 // Must be a TCL command
  98.     if (commandNo == cmdQuit)
  99.         Quit ();
  100.     else {
  101.         menuID = 0;
  102.         inherited::DoCommand (commandNo);
  103.         gSmalltalk->smalltalkCmd = FALSE;
  104.     }
  105. }
  106.  
  107.  
  108. //={OVERRIDE}==================================================================
  109. //     Pass responsibility for quitting over to Smalltalk
  110. //=============================================================================
  111. Boolean    CLStApp::Quit (void)
  112. {
  113.     menuID = 0xffff;
  114.     gSmalltalk->smalltalkCmd = FALSE;
  115.     return true;
  116. }
  117.  
  118.  
  119. //={OVERRIDE}==================================================================
  120. //     Create application's switchboard. (Uses CLStSwtchboard)
  121. //=============================================================================
  122.  
  123. void CLStApp::MakeSwitchboard (void)
  124. {
  125.     itsSwitchboard = new (CLStSwitchboard);
  126.     itsSwitchboard->ISwitchboard ();
  127. }
  128.  
  129.  
  130. //=============================================================================
  131. // Process a message alert
  132. //=============================================================================
  133. void CLStApp::DoMessageAlert (char *msg)
  134. {
  135.     Str255            theString, errorStr;
  136.     short            strID, itemID;
  137.  
  138.     strcpy ((char *)errorStr, msg);
  139.     strcpy ((char *)theString, (char *)errorStr);
  140.     
  141.     CtoPstr      ((char *)theString);
  142.     ParamText    (theString, NULL, NULL, NULL);
  143.     CautionAlert (k_OK_alert, NULL);
  144. }
  145.  
  146.  
  147. //=============================================================================
  148. // Process a Yes, No, Cancel alert
  149. //=============================================================================
  150. short CLStApp::DoYNCAlert (char *msg)
  151. {
  152.     Str255            theString, errorStr;
  153.     short            strID, itemID;
  154.  
  155.     InitCursor ();
  156.     strcpy ((char *)errorStr, msg);
  157.     strcpy ((char *)theString, (char *)errorStr);
  158.     
  159.     CtoPstr      ((char *)theString);
  160.     ParamText    (theString, NULL, NULL, NULL);
  161.     itemID = CautionAlert (k_YNC_alert, NULL);
  162.     switch (itemID) {
  163.         case kSetButtonID:
  164.             return (1);
  165.         case kCancelButtonID:
  166.             return (-1);
  167.         case kNoButtonID:
  168.             return (0);
  169.         default: ;
  170.     }
  171. }
  172.  
  173.  
  174. //=============================================================================
  175. // Put up the About Box
  176. //=============================================================================
  177. void CLStApp::DoAbout (long delay)
  178. {
  179.     EventRecord            theEvent;
  180.     GrafPtr                savePort;
  181.     long                ticksNow;
  182.     WindowPtr            aboutWindow;
  183.     PicHandle            aboutPic;
  184.     short                sposX, sposY;
  185.     
  186.     GetPort (&savePort);
  187.     
  188.     aboutWindow = GetNewWindow (kAboutBoxWIND, NULL, (WindowPtr)-1L);
  189.     if (!aboutWindow)
  190.         return;
  191.         
  192.     aboutPic = GetPicture (kAboutBoxPICT);
  193.     SetPort     (aboutWindow);
  194.     DrawPicture (aboutPic, &aboutWindow->portRect);
  195.     TextFont    (3);        /* Geneva */
  196.     TextSize    (9);
  197.     TextMode    (srcXor);
  198.     sposX = StringWidth (versionStr);
  199.     sposX = ((aboutWindow->portRect.right - aboutWindow->portRect.left) / 2) - (sposX / 2);
  200.     sposY = aboutWindow->portRect.bottom - 20;
  201.     MoveTo      (sposX, sposY);
  202.     DrawString  (versionStr);
  203.  
  204.     if (delay > 0L)
  205.         Delay (delay, &ticksNow);
  206.     else {    
  207.         GetNextEvent (keyDownMask + mDownMask, &theEvent);    /* Soak up any events  */
  208.                                                             /* left hanging around */
  209.         while (!GetNextEvent (keyDownMask + mDownMask, &theEvent))
  210.             SystemTask();
  211.     }
  212.     DisposeWindow (aboutWindow);
  213.     SetPort (savePort);
  214. }
  215.  
  216.  
  217. //={OVERRIDE}==================================================================
  218. // Just copy the SFReply to an instance variable.
  219. //=============================================================================
  220. void CLStApp::OpenDocument (SFReply *macReply)
  221. {
  222.     theFile = *macReply;    // Save the SFReply for use later
  223. }
  224.